﻿package org.openChart.display.chart 
{
	import flash.geom.Point;
	import org.openChart.display.DisplayElement;
	import org.openChart.display.DisplayGroup;
	import org.openChart.display.DisplayInterface;
	import org.openChart.meta.data.DataElement;
	/**
	 * ...
	 * @author Chongyuan
	 */
	public class DisplayPieElement extends DisplayElement
	{
		private var beginAngle_:Number;
		private var endAngle_:Number;
		private var longRadius_:Number;
		private var shotRadius_:Number;
		private var thickness_:Number;
		private var offset_:Number;
		private var valuePosition_:Point;
		private var viewAngle_:Number = 60;
		private var deviation_:Number;
		
		public function DisplayPieElement( element:DataElement, group:DisplayGroup ) 
		{
			super(element, group);
			viewAngle_ = element.getStyle().viewAngle;
			thickness_ = element.getStyle().thickness;
			this.offset_ = element.getStyle().offset;
		}
		
		public function set beginAngle( beginAngle_:Number ):void
		{
			this.beginAngle_ = beginAngle_;
		}
		
		public function get beginAngle():Number
		{
			return this.beginAngle_;
		}
		
		public function set endAngle( endAngle_:Number):void
		{
			this.endAngle_ = endAngle_;
		}
		
		public function get endAngle():Number
		{
			return this.endAngle_;
		}
		
		public function set longRadius( longRadius_:Number):void
		{
			this.longRadius_ = longRadius_;
		}
		
		public function get longRadius():Number
		{
			return this.longRadius_;
		}
		
		public function set shotRadius( shotRadius_:Number ):void
		{
			this.shotRadius_ = shotRadius_;
		}
		
		public function get shotRadius():Number
		{
			return this.shotRadius_;
		}
		
		public function set thickness( thickness_:Number ):void
		{
			this.thickness_ = thickness_;
		}
		
		public function get thickness():Number
		{
			return this.thickness_;
		}
		
		public function set offset( offset_:Number) :void
		{
			this.offset_ = offset_;
		}
		
		public function get offset():Number
		{
			return this.offset_;
		}
		
		public function get viewAngle():Number
		{
			return viewAngle_;
		}
		
		public function set viewAngle( viewAngle_:Number):void
		{
			this.viewAngle_ = viewAngle_;
		}
		
		public function set deviation( deviation_:Number):void
		{
			this.deviation_ = deviation_;
		}
		
		public function get deviation():Number
		{
			return deviation_;
		}
		
		public function get valuePosition():Point
		{
			if ( !valuePosition_ )
			{
				valuePosition_ = new Point();
				var middleAngle:Number;
				if (beginAngle_ > endAngle_)
				{
					middleAngle = (endAngle + beginAngle) / 2 + Math.PI;
				}
				else
				{
					middleAngle = (endAngle + beginAngle) / 2;
				}
				valuePosition_.x = this.position.x + longRadius * 0.8 * Math.cos(middleAngle);
				valuePosition_.y = this.position.y - shotRadius * 0.8 * Math.sin(middleAngle);
			}
			return valuePosition_;
		}
	}
	
}